<template>
  <el-dialog title="分配角色" :visible.sync="show">
    <el-checkbox-group v-model="value">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUserBase, sysUserAssignRoles } from '@/api/employees'
export default {
  data() {
    return {
      value: [],
      list: [],
      show: false,
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    // 获取角色列表
    async getData() {
      const res = await sysRole({ page: 1, pagesize: 1000 })
      // console.log(res)
      this.list = res.data.rows
    },
    // 关闭角色弹窗
    closeEvent() {
      this.show = false
      this.value = []
    },
    // 获取当前员工角色信息
    async getRoleById(id) {
      this.id = id
      const res = await sysUserBase(id)
      // console.log(res)
      this.value = res.data.roleIds
    },
    // 分配角色
    async submit() {
      await sysUserAssignRoles(this.id, this.value)
      this.$message.success('分配角色成功!')
      this.show = false
    }
  }
}
</script>

<style></style>
